﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;
using System.Runtime.InteropServices;
using System.IO;
using System.Diagnostics;
using WindowsFormsApplication1;



namespace PJAA_Inventory_and_AR___Prototype
{
    public partial class Main_Menu : Form
    {
        public bool click1 = false;
        public bool click2 = false;
        public bool click3 = false;

        private string currentuser;
        private string currentpass;
        string type;

        SQLMaster db;
        Back_up backup;

        public Main_Menu()
        {
            InitializeComponent();
            #region disable group boxes

            SalesGrpBox.Visible = false;
            SalesGrpBox.Enabled = false;

            //groupBox2.Visible = false;
            //groupBox2.Enabled = false;

            TransactionsGrpBox.Visible = false;
            TransactionsGrpBox.Enabled = false;

            InventoryGrpBox.Visible = false;
            InventoryGrpBox.Enabled = false;

            ViewGrpBox.Visible = false;
            ViewGrpBox.Enabled = false;
            #endregion
            //ADDED TO CHECK FOR CLICKED BUTTONS EVENT
            TransactionsBtn.Click += new EventHandler(this.GreetingBtn_Click);

            Clientlbl.Visible = false;
            label_client.Visible = false;

        }


        //ADDED TO CHECK FOR CLICKED BUTTONS EVENT
        #region ADDED TO CHECK FOR CLICKED BUTTONS EVENT
        void GreetingBtn_Click(Object sender,
                          EventArgs e)
        {


        }
        #endregion

        private void groupBox1_Enter(object sender, EventArgs e)
        {

        }

        private void label1_Click(object sender, EventArgs e)
        {

        }

        private void splitContainer1_Panel1_Paint(object sender, PaintEventArgs e)
        {

        }

        private void splitContainer1_Panel2_Paint(object sender, PaintEventArgs e)
        {

        }

        private void button1_Click(object sender, EventArgs e)
        {
            //Add_Client addCl = new Add_Client();
            ////addCl.TopLevel = false;
            ////addCl.Dock = DockStyle.Fill;
            ////addCl.Parent.   panel1.Controls.Add(GenReport);
            ////GenReport.Show();

            //addCl.ShowDialog();
            //
        }

        private void button6_Click(object sender, EventArgs e)
        {
            //Issue_Invoice issueInv = new Issue_Invoice(this);
            //issueInv.ShowDialog();
        }






        private void button7_Click(object sender, EventArgs e)
        {

        }











        private void label2_Click(object sender, EventArgs e)
        {

        }



        private void button3_Click(object sender, EventArgs e)
        {
            Generate_Report GenReport = new Generate_Report();
            GenReport.ShowDialog();
        }

        private void pictureBox1_Click(object sender, EventArgs e)
        {
            SQLMaster master = new SQLMaster();
            master.GoodsOnConsignmentClientHasDupli("cmp000010");
        }

        private void tmViewInventory_Tick(object sender, EventArgs e)
        {


            if (this.Width >= 502)
                this.tmViewSlide.Enabled = false;
            else
                this.Width += 10;
        }





        private void panel3_Paint(object sender, PaintEventArgs e)
        {

        }

        private void Main_Menu_Load(object sender, EventArgs e)
        {

        }



        private void TransactionsGrpBox_Enter(object sender, EventArgs e)
        {

        }

        private void SearchClientBtn_Click(object sender, EventArgs e)
        {
            //Search_Client searchCl = new Search_Client();
            //searchCl.TopLevel = false;
            //searchCl.Dock = DockStyle.Fill;
            //Main_Panel2.Controls.Add(searchCl);
            //searchCl.Show();
            //TransactionsGrpBox.Visible = false;
            //TransactionsGrpBox.Enabled = false;

            Search_Client searchCl = new Search_Client(this);
            searchCl.TopLevel = false;
            searchCl.Dock = DockStyle.Fill;
            Main_Panel2.Controls.Clear();
            Main_Panel2.Controls.Add(searchCl);
            searchCl.Show();
            TransactionsGrpBox.Visible = false;
            TransactionsGrpBox.Enabled = false;


            //List_Order list = new List_Order();
            //if (click1)
            //{
            //    list.TopLevel = false;
            //    list.Dock = DockStyle.Left;
            //    Main_Panel2.Controls.Add(list);
            //    list.Show();


            //}
        }

        public string _ClientName
        {
            set { label_client.Text = value; }
        }

        public string Title
        {
            set
            {Clientlbl.Text = value;}
        }



        private void AddClientBtn_Click(object sender, EventArgs e)
        {
            Add_Client addCl = new Add_Client("Add","");
            addCl.TopLevel = false;
            addCl.Dock = DockStyle.Fill;
            Main_Panel2.Controls.Clear();
            Main_Panel2.Controls.Add(addCl);
            addCl.Show();
            TransactionsGrpBox.Visible = false;
            TransactionsGrpBox.Enabled = false;



        }

        private void CompleteTransactionBtn_Click(object sender, EventArgs e)
        {
            Complete_Transaction CompleteTr = new Complete_Transaction(this);
            CompleteTr.TopLevel = false;
            CompleteTr.Dock = DockStyle.Fill;
            Main_Panel2.Controls.Clear();
            Main_Panel2.Controls.Add(CompleteTr);
            CompleteTr.Show();
            SalesGrpBox.Visible = false;
            SalesGrpBox.Enabled = false;
        }

        private void IssueInvoiceBtn_Click(object sender, EventArgs e)
        {
            Issue_Invoice issueInvoice = new Issue_Invoice(this);
            issueInvoice.TopLevel = false;
            issueInvoice.Dock = DockStyle.Fill;
            Main_Panel2.Controls.Clear();
            Main_Panel2.Controls.Add(issueInvoice);
            issueInvoice.Show();
            SalesGrpBox.Visible = false;
            SalesGrpBox.Enabled = false;
        }

        private void AddNewItemBtn_Click(object sender, EventArgs e)
        {
            Add_New_Item AddNew = new Add_New_Item();
            AddNew.TopLevel = false;
            AddNew.Dock = DockStyle.Fill;
            Main_Panel2.Controls.Clear();
            Main_Panel2.Controls.Add(AddNew);
            AddNew.Show();
            InventoryGrpBox.Visible = false;
            InventoryGrpBox.Enabled = false;
        }

        private void ReplenishInventoryBtn_Click(object sender, EventArgs e)
        {
            Replenish_Inventory repInv = new Replenish_Inventory();
            repInv.TopLevel = false;
            repInv.Dock = DockStyle.Fill;
            Main_Panel2.Controls.Clear();
            Main_Panel2.Controls.Add(repInv);
            repInv.Show();
            InventoryGrpBox.Visible = false;
            InventoryGrpBox.Enabled = false;
        }

        private void ViewClientsInventoryBtn_Click(object sender, EventArgs e)
        {
            View_Clients_Inventory viewClInv = new View_Clients_Inventory();
            viewClInv.TopLevel = false;
            viewClInv.Dock = DockStyle.Top;
            Main_Panel2.Controls.Clear();
            Main_Panel2.Controls.Add(viewClInv);
            viewClInv.Show();
            ViewGrpBox.Visible = false;
            ViewGrpBox.Enabled = false;
        }

        private void ViewCompletedTransactionBtn_Click(object sender, EventArgs e)
        {
            View_Completed_Transactions viewClTr = new View_Completed_Transactions();
            viewClTr.TopLevel = false;
            viewClTr.Dock = DockStyle.Fill;
            Main_Panel2.Controls.Clear();
            Main_Panel2.Controls.Add(viewClTr);
            viewClTr.Show();
            ViewGrpBox.Visible = false;
            ViewGrpBox.Enabled = false;
        }

        private void ViewAccountsReceivableBtn_Click(object sender, EventArgs e)
        {
            View_Accounts_Receivable viewAR = new View_Accounts_Receivable();
            viewAR.TopLevel = false;
            viewAR.Dock = DockStyle.Fill;
            Main_Panel2.Controls.Clear();
            Main_Panel2.Controls.Add(viewAR);
            viewAR.Show();
            ViewGrpBox.Visible = false;
            ViewGrpBox.Enabled = false;
        }

        private void ViewInventoryLevelBtn_Click(object sender, EventArgs e)
        {
            View_inventory_pjaa viewI = new View_inventory_pjaa();
            viewI.TopLevel = false;
            viewI.Dock = DockStyle.Fill;
            Main_Panel2.Controls.Clear();
            Main_Panel2.Controls.Add(viewI);
            viewI.Show();

            ViewGrpBox.Visible = false;
            ViewGrpBox.Enabled = false;
        }

        private void InventoryGrpBox_Enter(object sender, EventArgs e)
        {

        }

        private void ViewReportBtn_Click(object sender, EventArgs e)
        {
            Main_Panel2.Controls.Clear();
            Main_Panel2.Controls.Add(ViewGrpBox);

            TransactionsGrpBox.Visible = false;
            TransactionsGrpBox.Enabled = false;

            InventoryGrpBox.Visible = false;
            InventoryGrpBox.Enabled = false;


            SalesGrpBox.Visible = false;
            SalesGrpBox.Enabled = false;

            ViewGrpBox.Visible = true;
            ViewGrpBox.Enabled = true;

        }

        private void InventoryBtn_Click(object sender, EventArgs e)
        {
            Main_Panel2.Controls.Clear();
            Main_Panel2.Controls.Add(InventoryGrpBox);

            TransactionsGrpBox.Visible = false;
            TransactionsGrpBox.Enabled = false;

            InventoryGrpBox.Visible = true;
            InventoryGrpBox.Enabled = true;


            SalesGrpBox.Visible = false;
            SalesGrpBox.Enabled = false;

            ViewGrpBox.Visible = false;
            ViewGrpBox.Enabled = false;
        }

        private void TransactionsBtn_Click(object sender, EventArgs e)
        {
            Main_Panel2.Controls.Clear();
            Main_Panel2.Controls.Add(TransactionsGrpBox);

            TransactionsGrpBox.Visible = true;
            TransactionsGrpBox.Enabled = true;

            InventoryGrpBox.Visible = false;
            InventoryGrpBox.Enabled = false;


            SalesGrpBox.Visible = false;
            SalesGrpBox.Enabled = false;

            ViewGrpBox.Visible = false;
            ViewGrpBox.Enabled = false;

            //bool IsOpen = false;
            //FormCollection fc = Application.OpenForms;
            //foreach (Form f in fc)
            //{
            //    if (f.Name == "Transactions")
            //    {
            //        IsOpen = true;
            //        f.Focus();
            //        break;
            //    }
            //}

            //if (IsOpen == false)
            //{
            //    Transactions trans = new Transactions();
            //    trans.ShowDialog();
            //}
        }

        private void SalesBtn_Click(object sender, EventArgs e)
        {
            Main_Panel2.Controls.Clear();
            Main_Panel2.Controls.Add(SalesGrpBox);

            TransactionsGrpBox.Visible = false;
            TransactionsGrpBox.Enabled = false;

            InventoryGrpBox.Visible = false;
            InventoryGrpBox.Enabled = false;


            SalesGrpBox.Visible = true;
            SalesGrpBox.Enabled = true;

            ViewGrpBox.Visible = false;
            ViewGrpBox.Enabled = false;

            #region sliding effect of new window
            ////bool IsOpen = false;
            ////FormCollection fc = Application.OpenForms;
            ////foreach (Form f in fc)
            ////{
            ////    if (f.Name == "sales")
            ////    {
            ////        IsOpen = true;
            ////        f.Focus();
            ////        break;
            ////    }
            ////}

            ////if (IsOpen == false)
            ////{
            ////    sales sales= new sales();
            ////    sales.ShowDialog();
            ////}
            #endregion

            //Search_Client SrchClient = new Search_Client();
            //SrchClient.ShowDialog();

        }

        private void listView1_SelectedIndexChanged(object sender, EventArgs e)
        {

        }

        private void label2_Click_1(object sender, EventArgs e)
        {

        }

        private void label3_Click(object sender, EventArgs e)
        {

        }

        private void backUpToolStripMenuItem1_Click(object sender, EventArgs e)
        {
            DateTime backupTime = DateTime.Now;
            int year = backupTime.Year;
            int month = backupTime.Month;
            int day = backupTime.Day;
            int hour = backupTime.Hour;
            int minute = backupTime.Minute;
            int second = backupTime.Second;
            int ms = backupTime.Millisecond;

            String tmestr = backupTime.ToString();
            tmestr = "E:/Documents/Dropbox/OJT - PJAA/SQL files/dump files" + year + "-" + month + "-" + day + "-" + hour + "-" + minute + ".sql";
            StreamWriter file = new StreamWriter(tmestr);
            ProcessStartInfo proc = new ProcessStartInfo();
            string cmd = string.Format(@"-u{0} -p{1} -h{2} {3} > {4};", "root", "password", "localhost", "dbfile", "backup.sql");
            proc.FileName = "C:/Program Files/MySQL/MySQL Server 5.5/bin/mysqldump.exe";
            proc.RedirectStandardInput = false;
            proc.RedirectStandardOutput = true;
            proc.Arguments = cmd;//"-u root -p smartdb > testdb.sql";
            proc.UseShellExecute = false;
            Process p = Process.Start(proc);
            string res;
            res = p.StandardOutput.ReadToEnd();
            file.WriteLine(res);
            p.WaitForExit();
            file.Close();

        }

        private void backupToolStripMenuItem_Click(object sender, EventArgs e)
        {

            {
                saveFileDialog1.Filter = "sql files (*.sql)|*.sql";
                saveFileDialog1.FileName = "pjaamasscards";
                saveFileDialog1.Title = "Back-up Database";
                DialogResult save = saveFileDialog1.ShowDialog();
                if (save == DialogResult.OK)
                {
                    FileInfo fi = new FileInfo(saveFileDialog1.FileName);
                    string directory = fi.DirectoryName + "\\";
                    string file = fi.Name;
                    try
                    {
                        backup = new Back_up(directory, file);
                        backup.backup();
                        MessageBox.Show("Database Back-up Successful!", "Success", MessageBoxButtons.OK, MessageBoxIcon.Information);
                    }
                    catch
                    {
                        MessageBox.Show("Back-up Database Error!", "Error", MessageBoxButtons.OK, MessageBoxIcon.Hand);
                    }
                }
            }
        }

        private void backUpToolStripMenuItem1_Click_1(object sender, EventArgs e)
        {
            {

                {
                    saveFileDialog1.Filter = "sql files (*.sql)|*.sql";
                    saveFileDialog1.FileName = "pjaamasscards";
                    saveFileDialog1.Title = "Back-up Database";
                    DialogResult save = saveFileDialog1.ShowDialog();
                    if (save == DialogResult.OK)
                    {
                        FileInfo fi = new FileInfo(saveFileDialog1.FileName);
                        string directory = fi.DirectoryName + "\\";
                        string file = fi.Name;
                        try
                        {
                            backup = new Back_up(directory, file);
                            backup.backup();
                            MessageBox.Show("Database Back-up Successful!", "Success", MessageBoxButtons.OK, MessageBoxIcon.Information);
                        }
                        catch
                        {
                            MessageBox.Show("Back-up Database Error!", "Error", MessageBoxButtons.OK, MessageBoxIcon.Hand);
                        }
                    }
                }
            }
        }

        private void loadBackUpToolStripMenuItem_Click(object sender, EventArgs e)
        {
            {
                {
                    openFileDialog1.Filter = "sql files (*.sql)|*.sql";
                    openFileDialog1.FileName = "dental_db";
                    openFileDialog1.Title = "Import Database";
                    DialogResult open = openFileDialog1.ShowDialog();
                    if (open == DialogResult.OK)
                    {
                        FileInfo fi = new FileInfo(openFileDialog1.FileName);
                        string directory = fi.DirectoryName + "\\";
                        string file = fi.Name;
                        try
                        {
                            backup = new Back_up(directory, file);
                            backup.import();
                            MessageBox.Show("Database Import Successful!", "Success", MessageBoxButtons.OK, MessageBoxIcon.Information);
                        }
                        catch
                        {
                            MessageBox.Show("Import Database Error!", "Error", MessageBoxButtons.OK, MessageBoxIcon.Hand);
                        }
                    }
                }
            }
        }

        private void button1_Click_1(object sender, EventArgs e)
        {

        }

        private void button_addnewProductType_Click(object sender, EventArgs e)
        {
            AddNewProductForLookup AddNewProduct = new AddNewProductForLookup(this);
            AddNewProduct.TopLevel = false;
            AddNewProduct.Dock = DockStyle.Fill;
            Main_Panel2.Controls.Clear();
            Main_Panel2.Controls.Add(AddNewProduct);
            AddNewProduct.Show();
            InventoryGrpBox.Visible = false;
            InventoryGrpBox.Enabled = false;
        }


        private void exitToolStripMenuItem_Click_1(object sender, EventArgs e)
        {
            this.Close();
        }

        private void editClientInfoToolStripMenuItem_Click(object sender, EventArgs e)
        {
            Search_Client_edit edit = new Search_Client_edit();
            edit.TopLevel = false;
            edit.Dock = DockStyle.Fill;
            Main_Panel2.Controls.Clear();
            Main_Panel2.Controls.Add(edit);
            edit.Show();
        }

        private void editInventoryUnitPriceToolStripMenuItem_Click(object sender, EventArgs e)
        {
            EditMode_Search editModeSeach = new EditMode_Search("inventory");
            editModeSeach.TopLevel = false;
            editModeSeach.Dock = DockStyle.Fill;
            Main_Panel2.Controls.Clear();
            Main_Panel2.Controls.Add(editModeSeach);
            editModeSeach.Show();
        }

        private void editProductUnitPriceToolStripMenuItem_Click(object sender, EventArgs e)
        {
            EditMode_Search editModeSeach = new EditMode_Search("product");
            editModeSeach.TopLevel = false;
            editModeSeach.Dock = DockStyle.Fill;
            Main_Panel2.Controls.Clear();
            Main_Panel2.Controls.Add(editModeSeach);
            editModeSeach.Show();
        }
    }
}